/**
 * Created by uptain on 2017/8/15.
 */


const ja=new  Vue({
    el: '#main',
    data: {
        location:0,//地址页显示
        step2:0,
        mainpage:0,//主菜单页显示
        pictureGuid:0,//图片引导页
        setPicture:0,//图片设置页
        stepnow:0,//当前页面
        title:"基本信息",//顶部标题
        bobutton:"完成",//底部按钮
        none_msg:"请点击选择",
        newhouse:1,//是否为新建房源
        basic:1,//基础信息页面
        infrastructure:0,//基础设施
        introduce:0,//介绍页
        setIntroduce:0,//介绍页显示
        rotate:0,//图片旋转
        is_img_rotate:"addimg_heng",//图片旋转
        add_img_button_div:1,//
        mask_img_rule:0,//img规则弹出层
        img_rotate:{
            transform:""
        },
        intro_text:{//介绍页面显示控制
            area1:0,
            area2:0,
            area3:0,
            area4:0
        },
        boo_page:{
            page1:0,
            page2:0,
            page3:0,
            page4:0,
        },
        send_imgdata:[],
        token:localStorage.token,
        url:"appv2.fxj178.com/Home/HouseUpload/addAddress",
        add_address:{
            adcode:"",
            street:"",
            houseNumber:"",
            detailAddress:"",
            lng:"",
            lat:"",
            token:localStorage.token
        },

        chargeRule:{//发布规则页面控制
            main:0,
            menu:0,
            type1:0,
            type2:0,
            type3:0,
            type4:0,
            type5:0,
            footer:0
        },

        stepone_send:{
            roomType:0,
            roomIndoors:1,
            roomHalls:1,
            roomKitchens:1,
            roomToilets:1,
            roomVeranda:1,
            houseClassify:1,
            addGuest:1,
            addBed:1,
            houseArea:50,
            toiletType:0,
            token:localStorage.token,
            houseAddress:29773203956,
            houseTitle:"dssssssssss",
            rentType:0,
            bedLinen:1,
            other:0,
            appliance:[6,7,8],
            bedList:[],
        },
        basic_info:{//基础信息数据

            bedinfo:{
                width:"",
                length:""
            },
            bedtype:"",
            city_name:"",
            rent_type:0,
            house_location:0,
            house_area:"",
            house_type:0,
            house_unit:0,
            people_max:0,
            bed_amount:0,
            basic_thing:0,
            tolet_type:0,
            add_bed:0,
            change_sheet:0,
            add_person:0,
            province_block:"",
            city_area:"",
            city_ajax_data:""

        },
        house_describ:{//房源描述数据

            houseId:"21705403986",
            house_desc:"222",
            house_communication:"333",
            house_surrounding:"444"
        },
        house_img:{//房源图片数据
            imgbig:{
                rotate:0,
                src:"",
                order:"",
                txt:"",
                id:"",
                name:""
            },
            imgsmall:[]

        },
        img_all:0,

        publish_rule:{//房源发布规则数据
            token:localStorage.token,
            houseId:"",
            saveMsg:{
                discount_date:"1",
                attachment_fare:"8888",
                invoice:"1",
                foreignGuest:"1",
                min_day:"1",
                max_day:"5",
                cancelPaddingDate:"5",
                noUseDate:"1",
                price:"88",
                require:"ssssss",
                isDiscountSuccessive7:"1",
                succesive7_discount:"1",
                isDiscountSuccessive30:"1",
                succesive30_discount:"1",
                isDiscountWeekend:"1",
                isDiscountWeekend2:"1",
                discount_price:"88",
                discount_price2:"88",
                pledgeAmount:"100",
            },


        },
        bedSet:{//床位设置页面控制
            page1:0,
            page2:0,

        },
        text_content:"",
        textarea_number_max:0
    },
    methods: {
        next(){//首次发布房源
            console.log(this.stepnow)
            if(!this.newhouse){
                this.basic=0
                this[this.stepnow]=0;
                this.mainpage=1;
                this.introduce=0;
                this.setPicture=0;
                this.chargeRule.main=0;
                this.chargeRule.menu=0;
                return;
            }
            switch(this.stepnow)
            {
                case 0:

                    this.send_stepone_send()
                    if(this.boo_page.page1==0){
                        return
                    }

                    break;
                case 1:

                    this.send_house_describ()
                    this.introduce=0;
                    this.pictureGuid=1;
                    this.title="图片实例";
                    this.stepnow=2;
                    break;

                case 2:
                    this.pictureGuid=0;
                    this.setPicture=1;
                    this.title="房源图片"
                    this.stepnow=3;
                    break;
                case 3:

                    this.setPicture=0;
                    this.chargeRule.main=1;
                    this.chargeRule.menu=1;
                    this.title="发布规则";
                    this.stepnow=4;
                    break;
                case 4:
                    this.send_publish_rull()
                    this.chargeRule.main=0;
                    this.chargeRule.menu=0;
                    this.mainpage=1;
                    this.title="房源信息";
                    this.stepnow=0;
                    this.newhouse=0
                    break;
                case 5:
                    this.basic=1;
                    this.stepnow=0;
                    break;
            }
        },
        back(e){//去第e页

            this.basic=0
            this[this.stepnow]=0;
            this.mainpage=0;
            this.introduce=0;
            this.setPicture=0;
            this.chargeRule.main=0;
            this.chargeRule.menu=0;
            this.pictureGuid=0;
            this.location=0;
            if(!this.newhouse){//如果不是新发布

                this.basic=0
                this.mainpage=1;
                this.introduce=0;
                this.setPicture=0;
                this.chargeRule.main=0;
                this.chargeRule.menu=0;
                this.pictureGuid=0;
                return;
            }
            switch(e)
            {
                case 1:

                    this.introduce=1;
                    this.stepnow=1;
                    this.title="房源描述";
                    break;
                case 2:

                    this.pictureGuid=1;
                    this.title="图片实例";
                    this.stepnow=2;
                    break;

                case 3:

                    this.setPicture=1;
                    this.title="房源图片"
                    this.stepnow=3;
                    break;
                case 4:

                    this.chargeRule.main=1;
                    this.chargeRule.menu=1;
                    this.title="发布规则";
                    this.stepnow=4;
                    break;
                case 5:

                    this.mainpage=1;
                    this.title="房源信息";
                    this.stepnow=0;
                    this.newhouse=0
                    break;
                case 6:
                    this.basic=1;
                    this.infrastructure=0;
                    this.stepnow=0;
                    break;
            }
        },
        toBasic (){
            this.basic=1;
            this.mainpage=0
            this.newhouse=0
        },
        toIntroduce (){
            this.introduce=1;
            this.mainpage=0
            this.newhouse=0
        },
        toSetPicture (){
            this.setPicture=1;
            this.mainpage=0
            this.newhouse=0
        },

        toSetRule (){
        this.chargeRule.main=1;
        this.chargeRule.menu=1;
        this.mainpage=0;
        this.newhouse=0;
            console.log("cao")
        },
        toLocation(){
            this.basic=0;
            this.location=1
            this.stepnow=5;
        },
        toInfrastructure(){
            this.basic=0;
            this.infrastructure=1
            this.stepnow=5;
        },
        introduceChild(type){
            this.intro_text.area1=0
            this.intro_text.area2=0
            this.intro_text.area3=0
            this.intro_text.area4=0
            switch(type)
            {
                case 0:
                    this.introduce=1;
                    this.setIntroduce=0;
                    return;
                    break;
                case 1:
                    this.intro_text.area1=1
                    this.text_content="建议标题格式为\n\n地理位置+房源形容词+出租类型例如：\n\n新会展中心地铁1号线豪华套四整租1"
                    this.textarea_number_max=50
                    break;

                case 2:
                    this.intro_text.area2=1
                    this.text_content="    请介绍一下您的房子特色或者您想分享给房客的东西，让房客更好地了解您和您的家。\n例如：\n毗邻宽窄巷子的小两居，在这里你可以感受到历史文化的古朴气息，热闹与宁静并存。一杯茶，一本书，偷得浮生几时闲。若你我有缘，路过请停下脚步，我有酒，你有歌吗？"
                    this.textarea_number_max=500
                    break;

                case 3:
                    this.intro_text.area3=1
                    this.text_content="详细描述通过什么交通方式怎样到达您的家。\n例如：\n涌泉西站(西)，向前步行100米到天来国际广场；地铁4号线到地铁涌泉站D口出，向前步行200米到天来国际广场。"
                    this.textarea_number_max=500
                    break;

                case 4:
                    this.intro_text.area4=1
                    this.text_content="介绍一下房源周边情况，包括景区、商业街、超市、学校、医院等。\n例如：\n保安24小时值班，住宿安全。区内绿化覆盖，无噪音影响，宜晚饭后散步。小区周边有红旗连锁、家乐福超市，肯德基、德克士快餐店，夜市小吃一条街，步行200米到万达广场，500米到人民医院，1公里到大学城。"
                    this.textarea_number_max=500
                    break;
            }
            this.introduce=0;
            this.setIntroduce=1;
        },
        chargeRuleType(type){

            switch(type)
            {
                case 1:

                    this.chargeRule.type1=1;
                    break;
                case 2:

                    this.chargeRule.type2=1;
                    break;
                case 3:

                    this.chargeRule.type3=1;
                    break;
                case 4:

                    this.chargeRule.type4=1;
                    break;

                case 5:

                    this.chargeRule.type1=0;
                    this.chargeRule.type2=0;
                    this.chargeRule.type3=0;
                    this.chargeRule.type4=0;
                    this.chargeRule.menu=1;
                    this.chargeRule.footer=0;
                    return;
                break;
            }
            this.chargeRule.menu=0;
            this.chargeRule.footer=1;
        },
        bedPage(type){
            switch(type)
            {
                case 1:
                    this.bedSet.page2=0
                    this.bedSet.page1=1
                    break;
                case 2:
                    this.bedSet.page1=0
                    this.bedSet.page2=1
                    break;
                case 3:
                    this.bedSet.page1=0
                    this.bedSet.page2=0
                    this.basic=1;
                    return
                    break;
            }
            this.basic=0;
        },


        myswitch(id){
            var isActive = document.getElementById(id).classList.contains("mui-active");
            if(isActive){
                return true;
            }else{
                return false;
            }
        },

        send_house_describ(){
            var addJson=JSON.stringify(this.house_describ);
            console.log(addJson)

            var that=this
            var temp=new FormData();
            temp.append("houseId",this.house_describ.houseId);
            temp.append("house_desc",this.house_describ.house_desc);
            temp.append("house_communication",this.house_describ.house_communication);
            temp.append("house_surrounding",this.house_describ.house_surrounding);


            $.ajax({
                url: 'http://appv2.fxj178.com/home/houseUpload/describeAdd?token='+localStorage.token,
                type: 'post',
                data: temp,
                // 告诉jQuery不要去处理发送的数据
                processData : false,
                // 告诉jQuery不要去设置Content-Type请求头
               contentType:false,
            }).then(function (result) {
                var re={}
                re=JSON.parse( result )
                console.log(re);
                if(re.err==0){
                    mui.alert('提交成功',"房源描述","确认")
                }else{
                    mui.alert('提交失败',"房源描述","确认")
                    return
                }

            });
        },
        send_stepone_send(){


            var addJson=JSON.stringify(this.stepone_send);


            var that=this
            var temp=new FormData();
            addJson=addJson.toString()
            var  pppp=[1,2,3]
            console.log(addJson)

            $.ajax({
                 url: "http://appv2.fxj178.com/Home/HouseUpload/infoAdd?token="+localStorage.token,
                //url: "http://192.168.0.107/Home/test",
                type: 'post',
                data:{data:addJson},
                datatype:'html',
                success:function(e){
                    console.log(e)
                    var re={}
                    re=JSON.parse(e)
                    if(re.err==0){
                        that.boo_page.page1=1
                        that.house_describ.houseId=re.data.houseId
                        mui.alert('提交成功',"基础信息","确认")
                        that.basic=0;
                        that.introduce=1;
                        that.stepnow=1;
                        that.title="房源描述";
                        return;
                    }
                    if(re.err==1){

                        mui.alert('请返回重试',"提交失败","确认")
                        that.boo_page.page1=0

                    }

                },
                error:function(e){
                    console.log(e)
                }

            //}).then(function (result) {
            //    var re={}
            //    re=JSON.parse( result )
            //
            //    console.log(result);
            //    if(re.err==0){
            //        that.boo_page.page1=1
            //        that.house_describ.houseId=re.data.houseId
            //        mui.alert('提交成功',"基础信息","确认")
            //
            //        return;
            //    }
            //    if(re.err==1){
            //
            //        mui.alert('请返回重试',"提交失败","确认")
            //        that.boo_page.page1=0
            //        that.back(6)
            //    }
            //
            });
        },
        alert_test(){
            mui.alert('成功',"提交基础信息","确认")
        },
        change_img(){
            var that=this
            for(var img in this.house_img.imgsmall) {
                var imgs = this.house_img.imgsmall[img]
                var temp = new FormData();
                temp.append("order", imgs.order);
                temp.append("txt", imgs.txt);
                temp.append("rotate", imgs.rotate);
                temp.append("houseId",27716403916);
                temp.append("id", imgs.id);
                $.ajax({
                    url: 'http://appv2.fxj178.com/home/houseUpload/imgAdd?token=' + localStorage.token,
                    type: 'post',
                    data: temp,
                    processData: false,
                    contentType: false,
                }).then(function (result) {
                    var re = {}
                    re = JSON.parse(result)
                    console.log(re);
                    if (re.err == 0) {

                    }

                })
            }
        },
        dellet_img(){
            //删除图片
            var temp=new FormData();
            var that=this
            temp.append("houseId",this.house_describ.houseId);
            temp.append("id",this.house_img.imgbig.id);
            $.ajax({
                url: 'http://appv2.fxj178.com/home/houseUpload/imgDelete?token='+localStorage.token,
                type: 'post',
                data: temp,
                processData : false,
                contentType : false,
            }).then(function (result) {
                var re={}
                re=JSON.parse( result )
                console.log(re);
                if(re.err==0){

                    mui.alert('成功',"删除图片","确认")
                }
                else{
                    mui.alert('失败',"删除图片","确认")
                }

            });
        },
        send_publish_rull(){
            //发布规则
            var that=this.publish_rule.saveMsg
            var houseidtemp=this.house_describ.houseId

            $.ajax({
                url: 'http://appv2.fxj178.com/home/houseUpload/ruleAdd?token='+localStorage.token,
                type: 'post',
                contentType:"application/x-www-form-urlencoded",
                data: {

                        houseId: houseidtemp,
                        saveMsg: {
                            "discount-date":that.discount_date ,
                            "attachment-fare":that.attachment_fare ,
                            "invoice": that.invoice,
                            "foreignGuest":that.foreignGuest ,
                            "min-day":that.min_day ,
                            "max-day": that.max_day,
                            "cancelPaddingDate":that.cancelPaddingDate ,
                            "noUseDate":that.noUseDate ,
                            "price":that.price,
                            "require":that.require ,
                            "isDiscountSuccessive7":that.isDiscountSuccessive7 ,
                            "succesive7-discount" :that.succesive7_discount ,
                            "isDiscountSuccessive30": that.isDiscountSuccessive30,
                            "succesive30-discount":that.succesive30_discount ,
                            "isDiscountWeekend":that.isDiscountWeekend ,
                            "discount-price":that.discount_price ,
                            "pledgeAmount": that.pledgeAmount,
                            "pledgeMethod":1
                        }
                },


            }).then(function (result) {
                var re={}
                re=JSON.parse( result )
                console.log(re);
                if(re.err==0){
                    mui.alert('提交成功',"发布规则","确认")
                }else{
                    mui.alert('提交失败',"发布规则","确认")
                    return
                }
            });
        },
        send_address(){
            //发送添加地址信息
            var that=this
            var temp=new FormData();
            temp.append("street",this.add_address.street);
            temp.append("houseNumber",this.add_address.houseNumber);
            temp.append("detailAddress",this.add_address.detailAddress);
            temp.append("lng",this.add_address.lng);
            temp.append("lat",this.add_address.lat);
            temp.append("token",this.add_address.token);
            temp.append("adcode",this.add_address.adcode);
            $.ajax({
                url: "http://appv2.fxj178.com/Home/HouseUpload/addAddress",
                type: 'post',
                data: temp,
                datatype:'JSON',
                processData : false,
                contentType : false,

            }).then(function (result) {
                console.log(result);
                var re={}
                re=JSON.parse( result )
                that.stepone_send.houseAddress= re.data.id;
                if(re.err==0){
                    that.stepone_send.houseAddress= re.data.id;
                }
            });


        },

        addimg() {
            this.$refs.searchDom.click();
        },

        rotate_img(){
            if((this.rotate/90)%2==0){
                this.is_img_rotate="addimg_heng";
            }
            else{
                this.is_img_rotate="addimg_shu"
            }
            this.rotate+=90
            this.img_rotate.transform="rotate("+this.rotate+"deg)";
            this.house_img.imgbig.rotate=this.rotate;

        },
        is_cover_img(){

        },
        remark_img(){
            if(this.add_img_button_div){
                this.add_img_button_div=0;
            }
            else{
                this.add_img_button_div=1;
            }

        },

        mapchose(){
            //百度地图
            var that=this
            var center = Map.mapContext.getCenter();

            this.add_address.lat=center.lat;
            this.add_address.lng=center.lng;

                console.log("caole")

                $.ajax({
                    "url": "http://api.map.baidu.com/geocoder/v2/",
                    "data": {
                        location: that.add_address.lat + "," + that.add_address.lng,
                        output:"json",
                        ak:"j70AyjKaBB4euD5THDXZfNfLAl2wn22i"
                    },
                    "async":false,
                    "dataType": "jsonp",
                    "jsonp":"callback",
                    "jsonpCallback": "renderReverse",
                    "success": function (data) {
                        console.log(data)
                        that.add_address.lat=data.result.location.lat
                        that.add_address.lng=data.result.location.lng
                        that.add_address.adcode=data.result.addressComponent.adcode;
                        that.add_address.street=data.result.addressComponent.street;
                      console.log(that.add_address)
                    },
                    "error": function(data) {
                        alert("系统出错，请稍后重试")

                    }
                });

            console.log("caolechuuizio")


        },
        if_show_mask(){
          if(this.mask_img_rule){
              this.mask_img_rule=0
          }else{
              this.mask_img_rule=1
          }
        },

        imgadd(){


        },
        getcity(e){
//获得城市区县
            var th_is=this

            ajax({
                url: 'http://appv2.fxj178.com/home/index/getDistrict',
                type: 'post',
                data: {"cityCode":e}
            }).then(function (result) {
                console.log(result.data);
                th_is.basic_info.city_ajax_data=result.data
                var temparr=new  Array()
                var tempcao=new  Array()
                for(var i=0;i<result.data.length;i++){
                    tempcao={}
                    tempcao=result.data[i]
                    temparr.push(tempcao)
                }
                console.log(temparr)

                selectdistrict.updateWheel(0,temparr);

            });



            return
        },
        getInfrastructure(){


            var that=this

            $("span[data-value]").each(function () {
                var isActive=$(this).parent().find("div").hasClass("mui-active")
                if(isActive){
                    that.stepone_send.appliance.push($(this).attr("data-value"))
                }
            })
            this.back(6);


        },
        addClints(){
            var that=this
                if($("#addClints").hasClass("mui-active")){
                    that.stepone_send.addGuest=1
            }else{
                    that.stepone_send.addGuest=0
                }
        },
        isaddbed(){
            var that=this
            if($("#addbed").hasClass("mui-active")){
                that.stepone_send.addBed=1
            }else{
                that.stepone_send.addBed=0
            }
        },
        addBedFun(){
            var temp={}
            temp=this.basic_info.bedinfo;
            this.stepone_send.bedList.push(temp)
            var that=this.basic_info;
            $("#none_bed").after('<li class="mui-table-view-cell basicCell">' +
                '<span class="bedspan_l">'+that.bedtype+'</span>' +
                '<span class="bedspan_m">'+temp.width+'米宽*'+temp.length+'米长</span>' +
                '<span class="bedspan_r">'+temp.count+'张</span>' +
                '</li>')
            this.bedPage(1);

        },
        weekendSapecial(){
            var that=this
            if($("#isDiscountWe").hasClass("mui-active")){
                that.publish_rule.saveMsg.isDiscountWeekend=1
            }else{
                that.publish_rule.saveMsg.isDiscountWeekend=0
                that.publish_rule.saveMsg.discount_date=0
            }
        },
        weekendSapecial2(){
            var that=this
            if($("#isDiscountWe2").hasClass("mui-active")){
                that.publish_rule.saveMsg.isDiscountWeekend2=1
            }else{
                that.publish_rule.saveMsg.isDiscountWeekend2=0
            }
        },
        ren_long_days(){
            var that=this
            if($("#rent_long_days").hasClass("mui-active")){
                that.publish_rule.saveMsg.isDiscountSuccessive7=1

            }else{
                that.publish_rule.saveMsg.isDiscountSuccessive7=0

            }
        },
        ren_long_days1(){
            var that=this
            if($("#rent_long_days1").hasClass("mui-active")){

                that.publish_rule.saveMsg.isDiscountSuccessive30=1
            }else{

                that.publish_rule.saveMsg.isDiscountSuccessive30=0
            }
        },
        is_forein_goust(){

            var that=this
            if($("#forein_goust").hasClass("mui-active")){
                that.publish_rule.saveMsg.foreignGuest=1

            }else{
                that.publish_rule.saveMsg.foreignGuest=0
            }
        },
        is_invoice(){

            var that=this
            if($("#invoice").hasClass("mui-active")){
                that.publish_rule.saveMsg.invoice=1
            }else{
                that.publish_rule.saveMsg.invoice=0
            }
        }


    }
})


//var fileInput = document.getElementById("addimgca");
//   fileInput.addEventListener('change', function () {
//            var file = this.files[0];
//            var reader = new FileReader();
//            var filename=file.name
//
//           // 监听reader对象的的onload事件，当图片加载完成时，把base64编码賦值给预览图片
//           reader.addEventListener("load", function () {
//               var temp={
//                   name:filename,
//                   rotate:"",
//                   iscover:"",
//                   src: reader.result
//               }
//                console.log(temp)
//               ja.imgpush(temp);
//               var img = document.createElement("img");
//               img.src= reader.result;
//               document.getElementById("addimg-sam").append(img);
//               }, false);
//          // 调用reader.readAsDataURL()方法，把图片转成base64
//          reader.readAsDataURL(file);
//       }, false);



var fileInput = document.getElementById("addimgca");
fileInput.addEventListener('change', function (){
    var allfile=this.files
    var file = this.files[0];
    var reader = new FileReader();
    var filename=file.name;
    var classname=filename.split('.')[0]

    reader.addEventListener("load", function () {

        var img = document.createElement("img");
        img.src= reader.result;
        img.setAttribute("class",filename)

        ja.house_img.imgbig.src= img.src;




        var houseidtemp=ja.house_describ.houseId

        for(var i=0;i<allfile.length;i++) {



            var formdata = new FormData();
            formdata.append("token", localStorage.token);
            formdata.append("houseId", houseidtemp);
            formdata.append("img", allfile[i]);
            $.ajax({
                url: 'http://fxj178.com/home/AppUploadImg/imgUpload?token='+localStorage.token,
                type: 'post',
                data: formdata,
                processData: false,
                // 告诉jQuery不要去设置Content-Type请求头
                contentType: false,
            }).then(function (result) {
                japan={}
                var re={}
                re=JSON.parse( result )
                console.log(re);
                if(re.err==0){
                    /******/



                    ja.house_img.imgbig.rotate="";
                    ja.house_img.imgbig.txt=""
                    ja.house_img.imgbig.src= img.src;
                    ja.house_img.imgbig.name=filename
                    ja.house_img.imgbig.order=ja.img_all+1
                    ja.house_img.imgbig.id=re.data;


                    var japan={}

                    japan.rotate=ja.house_img.imgbig.rotate
                    japan.txt=ja.house_img.imgbig.txt
                    japan.id=ja.house_img.imgbig.id
                    japan.order=ja.house_img.imgbig.order
                    japan.rotate=ja.house_img.imgbig.rotate
                    Vue.set(ja.house_img.imgsmall, classname,japan);
                    ja.send_imgdata.push(japan);
                    ja.img_all=ja.img_all+1
                    document.getElementById("addimg-sam").append(img);
                    document.getElementById("addimg-sam").lastElementChild.addEventListener('click', function (){
                        Vue.set(ja.house_img.imgsmall, classname,japan);
                        ja.send_imgdata.push(japan);
                        ja.house_img.imgbig=ja.house_img.imgsmall[classname]

                        ja.house_img.imgbig.src=img.src;
                    })



                }

            });
        }

    }, false);
    reader.readAsDataURL(file);


}, false);


var city_data_fliter=function(e){

    var reurn_data=[];
    var city_data={
        id:"",
        value:""
    };
    for(var i=0;i<CITYS[e].length;i++){
        city_data={}
        city_data.id=CITYS[e][i].value;
        city_data.value=CITYS[e][i].text;

        reurn_data.push(city_data);
    }
    return reurn_data
}


var housearea = new MobileSelect({
    trigger: '#house_area',
    title: '地区选择',
    wheels: [
        {data:[
            {id:'110000',value:'北京',childs:city_data_fliter(110000)},
            {id:'310000',value:'上海',childs:city_data_fliter(310000)},
            {id:'130000',value:'天津',childs:city_data_fliter(120000)},
            {id:'500000',value:'重庆',childs:city_data_fliter(500000)},
            {id:'440000',value:'广东',childs:city_data_fliter(440000)},
            {id:'510000',value:'四川',childs:city_data_fliter(510000)},
            {id:'330000',value:'浙江',childs:city_data_fliter(330000)},
            {id:'520000',value:'贵州',childs:city_data_fliter(520000)},
            {id:'210000',value:'辽宁',childs:city_data_fliter(210000)},
            {id:'320000',value:'江苏',childs:city_data_fliter(320000)},
            {id:'350000',value:'福建',childs:city_data_fliter(350000)},
            {id:'130000',value:'河北',childs:city_data_fliter(130000)},
            {id:'410000',value:'河南',childs:city_data_fliter(410000)},
            {id:'220000',value:'吉林',childs:city_data_fliter(220000)},
            {id:'230000',value:'黑龙江',childs:city_data_fliter(230000)},
            {id:'440000',value:'山东',childs:city_data_fliter(370000)},
            {id:'340000',value:'安徽',childs:city_data_fliter(340000)},
            {id:'450000',value:'广西',childs:city_data_fliter(450000)},
            {id:'460000',value:'海南',childs:city_data_fliter(460000)},
            {id:'150000',value:'内蒙古',childs:city_data_fliter(150000)},
            {id:'140000',value:'山西',childs:city_data_fliter(140000)},
            {id:'640000',value:'宁夏',childs:city_data_fliter(640000)},
            {id:'620000',value:'甘肃',childs:city_data_fliter(620000)},
            {id:'610000',value:'陕西',childs:city_data_fliter(610000)},
            {id:'630000',value:'青海',childs:city_data_fliter(630000)},
            {id:'420000',value:'湖北',childs:city_data_fliter(420000)},
            {id:'430000',value:'湖南',childs:city_data_fliter(430000)},
            {id:'360000',value:'江西',childs:city_data_fliter(360000)},
            {id:'530000',value:'云南',childs:city_data_fliter(530000)},
            {id:'650000',value:'新疆',childs:city_data_fliter(650000)},
            {id:"540000",value:'西藏',childs:city_data_fliter(540000)}
        ]}
    ],
    position:[0,1],
    callback:function(indexArr, data){

        ja.basic_info.province_block=data[0].value+data[1].value
        console.log(ja.basic_info.province_block)

        console.log(data); //返回选中的json数据
        ja.getcity(data[1].id);


        var myGeo = new BMap.Geocoder();
        // 将地址解析结果显示在地图上,并调整地图视野
        myGeo.getPoint(ja.basic_info.province_block, function(point){
            if (point) {
                Map.mapContext.centerAndZoom(point, 13);
                Map.mapContext.addOverlay(new BMap.Marker(point));
            }else{
                alert("您选择地址没有解析到结果!");
            }
        }, ja.basic_info.province_block);
    }
});

var selectdistrict = new MobileSelect({
    trigger: '#selectdistrict',
    title: '区县选择',
    wheels: [
        {
            data:[{}]
        }
    ],
    callback:function(indexArr, data){
    console.log(data[0].value)
        ja.basic_info.city_area=data[0].value;
        ja.add_address.adcode=data[0].id;


        var myGeo = new BMap.Geocoder();
        // 将地址解析结果显示在地图上,并调整地图视野
        myGeo.getPoint(ja.basic_info.city_area, function(point){
            if (point) {
                Map.mapContext.centerAndZoom(point, 13);
                Map.mapContext.addOverlay(new BMap.Marker(point));
            }else{
                alert("您选择地址没有解析到结果!");
            }
        }, ja.basic_info.province_block);
    }
});



var cutselect = new MobileSelect({
    trigger: '#day7',
    title: '折扣选择',
    wheels: [
        {data:[
            {id:'9',value:'9'},
            {id:'8',value:'8'},
            {id:'7',value:'7'},
            {id:'6',value:'6'},
            {id:'5',value:'5'},
            {id:'4',value:'4'},
            {id:'3',value:'3'},
            {id:'2',value:'2'},
            {id:'1',value:'1'},
            {id:'0',value:'0'},

        ]},
        {data:[
            {id:'9',value:'9'},
            {id:'8',value:'8'},
            {id:'7',value:'7'},
            {id:'6',value:'6'},
            {id:'5',value:'5'},
            {id:'4',value:'4'},
            {id:'3',value:'3'},
            {id:'2',value:'2'},
            {id:'1',value:'1'},
            {id:'0',value:'0'},
        ]}
    ],
    callback:function(indexArr, data){
        ja.publish_rule.saveMsg.succesive7_discount=(data[0].id+data[1].id)/10


       // console.log(data); //返回选中的json数据
    }
});




var housearea = new MobileSelect({
    trigger: '#day30',
    title: '折扣选择',
    wheels: [
        {data:[
            {id:'9',value:'9'},
            {id:'8',value:'8'},
            {id:'7',value:'7'},
            {id:'6',value:'6'},
            {id:'5',value:'5'},
            {id:'4',value:'4'},
            {id:'3',value:'3'},
            {id:'2',value:'2'},
            {id:'1',value:'1'},
            {id:'0',value:'0'},

        ]},
        {data:[
            {id:'9',value:'9'},
            {id:'8',value:'8'},
            {id:'7',value:'7'},
            {id:'6',value:'6'},
            {id:'5',value:'5'},
            {id:'4',value:'4'},
            {id:'3',value:'3'},
            {id:'2',value:'2'},
            {id:'1',value:'1'},
            {id:'0',value:'0'},
        ]}
    ],
    callback:function(indexArr, data){
        ja.publish_rule.saveMsg.succesive30_discount=(data[0].id+data[1].id)/10
        //console.log(data); //返回选中的json数据
    }
});



var housearea = new MobileSelect({
    trigger: '#bed_kind',
    title: '床铺类型',
    wheels: [
        {data:[
            {id:'1',value:'双人床'},
            {id:'2',value:'单人床'},
            {id:'3',value:'沙发'},
            {id:'4',value:'榻榻米'},
            {id:'5',value:'上下铺'},
        ]}
    ],
    callback:function(indexArr, data){

        ja.basic_info.bedinfo.type=data[0].id
        ja.basic_info.bedtype=data[0].value
        // //返回选中的json数据
    }
});



var housearea = new MobileSelect({
    trigger: '#bed_amount',
    title: '数量',
    wheels: [
        {data:[
            {id:'1',value:'1'},
            {id:'2',value:'2'},
            {id:'3',value:'3'},
            {id:'4',value:'4'},
            {id:'35',value:'5'},
        ]}
    ],
    callback:function(indexArr, data){
        ja.basic_info.bedinfo.count=data[0].id
       // console.log(data); //返回选中的json数据
    }
});



var housearea = new MobileSelect({
    trigger: '#wekends',
    title: '选择',
    wheels: [
        {data:[
            {id:'1',value:'周日'},
            {id:'2',value:'周六'},
            {id:'3',value:'周六/周日'},

        ]}
    ],
    callback:function(indexArr, data){
        ja.publish_rule.saveMsg.discount_date=data[0].id
       // console.log(data); //返回选中的json数据
    }
});


var Housetype = new MobileSelect({
    trigger: '#housetype',
    title: '户型选择',
    wheels: [
        {data:[
            {id:'1',value:'1室'},
            {id:'2',value:'2室'},
            {id:'3',value:'3室'},
            {id:'4',value:'4室'},
            {id:'5',value:'5室'},
            {id:'6',value:'6室'}
        ]},
        {data:[
            {id:'1',value:'1厅'},
            {id:'2',value:'2厅'},
            {id:'3',value:'3厅'},
            {id:'4',value:'4厅'},
            {id:'5',value:'5厅'}
        ]},
        {data:[
            {id:'1',value:'1卫'},
            {id:'2',value:'2卫'},
            {id:'3',value:'3卫'},
            {id:'4',value:'4卫'},
            {id:'5',value:'5卫'}
        ]},{data:[
            {id:'1',value:'1厨'},
            {id:'2',value:'2厨'},
            {id:'3',value:'3厨'},
            {id:'4',value:'4厨'},
            {id:'5',value:'5厨'}
        ]},{data:[
            {id:'1',value:'1阳台'},
            {id:'2',value:'2阳台'},
            {id:'3',value:'3阳台'},
            {id:'4',value:'4阳台'},
            {id:'5',value:'5阳台'}
        ]},

    ],
    callback:function(indexArr, data){
        console.log(data)

            ja.basic_info.house_unit=data;

            ja.stepone_send.roomIndoors=parseInt(data[0].id)
            ja.stepone_send.roomHalls=parseInt(data[1].id)
            ja.stepone_send.roomToilets=parseInt(data[2].id)
            ja.stepone_send.roomKitchens=parseInt(data[3].id)
            ja.stepone_send.roomVeranda=parseInt(data[4].id)
    }
});

var people_max = new MobileSelect({
    trigger: '#peoplemax',
    title: '可住人数',
    wheels: [
        {data:[
            {id:'1',value:'1'},
            {id:'2',value:'2'},
            {id:'3',value:'3'},
            {id:'4',value:'4'},
            {id:'5',value:'5'},
            {id:'6',value:'6'},
            {id:'7',value:'7'},
            {id:'8',value:'8'},
            {id:'9',value:'9+'},

        ]}
    ],
    callback:function(indexArr, data){
        console.log(data)
        ja.stepone_send.houseClassify=parseInt(data[0].value)
       // console.log(data); //返回选中的json数据
    }
});





var chuangdan = new MobileSelect({
    trigger: '#chuangdan',
    title: '卫生间',
    wheels: [
        {data:[
            {id:'1',value:'每日一换'},
            {id:'0',value:'每客一换'},
        ]}
    ],
    callback:function(indexArr, data){
        ja.stepone_send.bedLinen=parseInt(data[0].id)
        // //返回选中的json数据
    }
});


var Toilet = new MobileSelect({
    trigger: '#Toilet',
    title: '卫生间',
    wheels: [
        {data:[
            {id:'0',value:'独立卫生间'},
            {id:'1',value:'公用卫生间'},
        ]}
    ],
    callback:function(indexArr, data){
        ja.stepone_send.toiletType=parseInt(data[0].id)
        // //返回选中的json数据
    }
});


var people_max = new MobileSelect({
    trigger: '#least_day',
    title: '最少入住天数',
    wheels: [
        {data:[
            {id:'1',value:'1天'},
            {id:'2',value:'2天'},
            {id:'3',value:'3天'},
            {id:'4',value:'4天'},
            {id:'5',value:'5天'},
            {id:'6',value:'6天'},
            {id:'7',value:'7天'},
            {id:'8',value:'8天'},
            {id:'9',value:'9天'},

        ]}
    ],
    callback:function(indexArr, data){
        ja.publish_rule.saveMsg.min_day=data[0].id
       // console.log(data); //返回选中的json数据
    }
});


var people_max = new MobileSelect({
    trigger: '#most_day',
    title: '最多入住天数',
    wheels: [
        {data:[
            {id:'0',value:'不限'},
            {id:'5',value:'5天'},
            {id:'10',value:'10天'},
            {id:'15',value:'15天'},
            {id:'20',value:'20天'},
            {id:'30',value:'30天'},
            {id:'40',value:'40天'},
            {id:'50',value:'50天'},
            {id:'60',value:'60天'},
            {id:'90',value:'90天'},
            {id:'120',value:'120天'},
            {id:'180',value:'180天+'}

        ]}
    ],
    callback:function(indexArr, data){
        ja.publish_rule.saveMsg.max_day=data[0].id
        //console.log(data); //返回选中的json数据
    }
});




var house_type = new MobileSelect({
    trigger: '#house_type',
    title: '房源类型',
    wheels: [
        {data:[
            {id:'1',value:'普通类型'},
            {id:'2',value:'公寓'},
            {id:'3',value:'别墅'},
        ]}
    ],
    callback:function(indexArr, data){
        ja.stepone_send.house_type=parseInt(data[0].id)
    }
});


var houserent_type = new MobileSelect({
    trigger: '#rent_type',
    title: '出租类型',
    wheels: [
        {data:[
            {id:'0',value:'整套出租'},
            {id:'1',value:'单间出租'},
        ]}
    ],
    callback:function(indexArr, data){
        console.log(data)
        ja.stepone_send.roomType=parseInt(data[0].id)
        console.log(ja.stepone_send.rent_type)
    }

});


var Map={
    mapContext:null,
        decoder:null,
        point:null,
        marker:null,
}

function loadJScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://api.map.baidu.com/api?v=2.0&ak=4mfFj7Ph9nym7oa4e9EkW24KDQF4wavl&callback=init";
    document.body.appendChild(script);
}

function init() {

    var map = new BMap.Map("map");            // 创建Map实例
    Map.mapContext=map;
    Map.decoder=new BMap.Geocoder();
    var point = new BMap.Point(116.404, 39.915); // 创建点坐标
    map.centerAndZoom(point,15);
    map.enableScrollWheelZoom();                 //启用滚轮放大缩小
    map.addEventListener("click", function(){
        alert("您点击了地图。");
        var center = map.getCenter();
        console.log(center)
        var marker = new BMap.Marker(center);// 创建标注
        map.addOverlay(marker); // 将标注添加到地图中
        marker.disableDragging();
        ja.add_address.lat=center.lat;
        ja.add_address.lng=center.lng;


    });

    var myGeo = new BMap.Geocoder();
    // 将地址解析结果显示在地图上,并调整地图视野
    myGeo.getPoint("成都市", function(point){
        if (point) {
            map.centerAndZoom(point, 13);
            map.addOverlay(new BMap.Marker(point));
        }else{
            alert("您选择地址没有解析到结果!");
        }
    }, "成都市");

    var top_left_navigation = new BMap.NavigationControl({
        type:BMAP_NAVIGATION_CONTROL_LARGE,
        enableGeolocation: true
    });

    map.addEventListener("click", function(){
        alert("您点击了地图。");
    });
}






window.onload = loadJScript;